<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: HCZ <huangchengze@qq.com> 
// +----------------------------------------------------------------------

namespace app\index\controller\api;
use app\common\controller\Api;
/**
 * 首页API
 * @package app\index\api
 * @author HCZ<huangchengze@qq.com>
 */
class Index extends Api{
	
	/**
	 * 统计审核状态
	 */
	public function countAuditItem($scope = null){
		$where = '';
		if($scope){
			$where = ' where enterpriseId='.$scope;
		}
		$info = Db()->query("select 
					count(id) as 'all',
					count(case when status = 0 then id end) as 'unaudited',
					count(case when status = 1 then id end) as 'under_review',
					count(case when status = 2 then id end) as 'success',
					count(case when status = 3 then id end) as 'deny',
					count(case when status = 4 then id end) as 'ignore' from etrol_wfiteminfo".$where);
		return json(['code'=>1,'msg'=>'审核状态','data'=>$info]);
	}
	
	public function countAlarm($scope = null){
		$where = '';
		if($scope){
			$where = ' where d.enterpriseId='.$scope;
		}
		$info = Db()->query("select 
					count(a.id) as 'all',
					count(case when a.status = 0 then a.id end) as 'unread',
					count(case when a.status = 1 then a.id end) as 'pending',
					count(case when a.status = 2 then a.id end) as 'ignore',
					count(case when a.status = 3 then a.id end) as 'handled' from etrol_alarm as a 
					INNER JOIN etrol_dangersource as d ON a.dangerSourceId=d.id".$where);
		return json(['code'=>1,'msg'=>'报警状态','data'=>$info]);
	}
}
